import util from "@/libs/util";

export default ({ request }) => ({
  /**
   * @description 获取商品列表
   * @param {Object} data
   */
  GOODS_LIST(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.id = userinfo ? userinfo.user_id : null;

    return request({
      url: "/data/v1/goodList",
      method: "post",
      data: data,
    });
  },
  /**
   * 商品详情
   * @param {*} data
   * @returns
   */
  GOODS_DETAILS(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.user_id = userinfo ? userinfo.user_id : null;

    return request({
      url: "/data/v1/goodDetails",
      method: "post",
      data: data,
    });
  },
  /**
   * 商品收藏+取消收藏
   * @param {*} data
   * @returns
   */
  GOODS_COLLECTION(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.user_id = userinfo ? userinfo.user_id : null;

    return request({
      url: "/data/v1/goodCollection",
      method: "post",
      data: data,
    });
  },
  /**
   * 商品推荐（用于拉动）
   */
  GOODS_RECOMMEND(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.id = userinfo ? userinfo.user_id : null;
    return request({
      url: "/data/v1/recommend",
      method: "post",
      data: data,
    });
  },
  /**
   * 商品批量收藏+取消收藏
   * @param {*} data
   * @returns
   */
  GOODS_COLLECTION_ALL(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.user_id = userinfo ? userinfo.user_id : null;
    return request({
      url: "/data/v1/goodCollection",
      method: "post",
      data: data,
    });
  },
  /**
   * 商品收藏列表
   * @param {*} data
   * @returns
   */
  GOODS_COLLECTION_LIST(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.id = userinfo ? userinfo.user_id : null;

    return request({
      url: "/data/v1/goodCollectionList",
      method: "post",
      data: data,
    });
  },
});
